class CORSMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)
        # 允许跨域的域名列表，可以使用'*'允许所有
        response['Access-Control-Allow-Origin'] = '*'
        # 允许的头部
        response['Access-Control-Allow-Headers'] = 'Content-Type'
        # 允许的请求方法
        response['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE'
        return response
